package com.zzyl.controller;


import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDTO;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/nursing")
@RestController
@Api(tags = "护理计划模块")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping("/plan")
    @ApiOperation("查询所有护理计划")
    public ResponseResult getAllPlan(){
        List<NursingPlanVO> list = nursingPlanService.getAllPlan();
        return ResponseResult.success(list);
    }

    @PostMapping("/plan")
    @ApiOperation("新增护理计划")
    public ResponseResult addPlan(@RequestBody NursingPlanDTO dto){
        nursingPlanService.addPlan(dto);
        return ResponseResult.success();
    }

    @GetMapping("/plan/search")
    @ApiOperation("条件分页查询")
    public ResponseResult list(@ApiParam(value = "护理计划名称") String name,
                               @RequestParam(defaultValue = "1")@ApiParam(value = "页码") Integer pageNum,
                               @RequestParam(defaultValue = "10")@ApiParam(value = "每页大小") Integer pageSize,
                               @ApiParam(value = "护理计划状态") Integer status){
        return nursingPlanService.list(name,pageNum,pageSize,status);
    }

    @GetMapping("/plan/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult getById(@PathVariable Integer id){
        NursingPlanVO nursingPlanVO = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVO);
    }

    @PutMapping("/plan/{id}")
    @ApiOperation(value = "修改护理计划")
    public ResponseResult updatePlan(@RequestBody NursingPlanDTO dto){
        nursingPlanService.updatePlan(dto);
        return ResponseResult.success();
    }

    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "删除护理计划")
    public ResponseResult delete(@PathVariable Integer id){
        nursingPlanService.delete(id);
        return ResponseResult.success();
    }

    @PutMapping("/plan/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        nursingPlanService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
